import Taro from '@tarojs/taro';
import {Image, View} from '@tarojs/components';
import {connect} from "@tarojs/redux";
import {request, unite} from '../../../utils/index';
import head from "../../../asset/images/head.png";
import './trainCourse.scss';
import None from "../../../asset/images/none.png";


class MyCoupon extends Taro.Component {
    config = {
        navigationBarTitleText: '排课',
        navigationBarBackgroundColor: '#F6F7F7',
    };

    state = {
        dataList: [],
    };

    componentDidShow() {
        this.init();
    }

    init = () => {
        const params = {
            url: '/wx/coach/myClassInfo',
            data:{}
        };
        request(params).then(res => {
            Taro.stopPullDownRefresh(); //停止当前页面下拉刷新
            if (res) {
                if(res.code == 200) {
                    if (res && res.data) {
                        this.setState({
                            dataList: res.data,
                        })
                    }
                }
            }
        })
    };

    render() {
        const {dataList} = this.state;
        return (
            <View className="myPage">
                {dataList.length != 0 ? (
                    <View className="course-wrap">
                        {dataList.map((val, i) => (
                            <View key={i}>
                                <View className="course-names">{val.scaleName}</View>
                                {val.weiXinMyClassInfoResp.map((item, index) => (
                                    <View className="course-list flex-lr" key={index} onClick={() => {Taro.navigateTo({url: '../coursey-detail/courseDetail?id='+item.classRefId})}}>
                                        <Image className="course-img" mode="widthFix" src={item.avatar}/>
                                        <View className="course-content flex-lr">
                                            <View>
                                                <View className="course-name text-overflow">{item.className}</View>
                                                <View className="flex-l">
                                                    <View className="course-g flex-center">{item.classScaleName}</View>
                                                    <View>¥{item.price}/节</View>
                                                </View>
                                                {/*<View className="flex-l">*/}
                                                {/*    {item.labelNames.map((value, is) => (*/}
                                                {/*        <View className="course-gg flex-center" key={is}>{value}</View>*/}
                                                {/*    ))}*/}
                                                {/*</View>*/}
                                            </View>
                                            {val.studentNum == '' ? (
                                                <View className="course-btn course-btn-next-sh flex-center">审核中</View>
                                            ) : (
                                                <View className="course-btn course-btn-next flex-center" onClick={(e) => { e.stopPropagation();Taro.navigateTo({url: '../arranging-coursey/arrangingCoursey?id=' + item.classRefId+'&classId='+item.classId})}}>{item.dispatchStatus ? '查看排课' : '排课'}</View>
                                            )}
                                        </View>
                                    </View>
                                ))}
                            </View>
                        ))}
                        <View className="course-add-btn">
                            <View className="btn flex-center" onClick={() => {Taro.navigateTo({url: '../add-coursey/addCourse'})}}>添加课程</View>
                        </View>
                    </View>
                ) : (
                    <View className="none-wrap-page">
                        <Image className="none-img" src={None}/>
                        <View>暂无课程…</View>
                        <View className="none-max-btn" onClick={() => {Taro.navigateTo({url: '../add-coursey/addCourse'})}}>添加课程</View>
                    </View>
                )}
            </View>
        )
    }
}

const mapStateToProps = state => {
    let {} = state;
    return {
    }
};

const mapDispatchToProps = {
};

export default connect(mapStateToProps, mapDispatchToProps)(MyCoupon);



